import Vue from 'vue'
import Router from 'vue-router'
import Cookies from 'js-cookie'

Vue.use(Router)

import Layout from '@/layout'
import MechanicOrder from '@/layout/mechanicOrder'

let userType = null;
let hidden = true;
let hidden3 = true;
let hidden2 = true;
let hidden4 = true;
let hidden5 = true;
let hidden6 = true;
let affix = false
if (Cookies.get("user")) {
  userType = JSON.parse(Cookies.get("user"))?.userType || null;
  if (userType === 1) {
    hidden = false;
    hidden3 = false;
    hidden4 = false;
    hidden5 = false;
    hidden6 = false;
  }
  if (userType === 2) {
    hidden2 = false;
    // hidden3 = false;
    affix = true
  }
  if (userType === 3) {
    hidden3 = false;
    affix = true
  }
  if (userType === 4) {
    hidden4 = false;
    affix = true
  }
  if (userType === 5) {
    hidden5 = false;
  }
  if (userType === 6) {
    hidden2 = false;
    hidden6 = false;
  }
  if (userType === 7) {
    hidden6 = false;
  }
  if (userType === 8) {
    hidden6 = false;
  }
}

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      hidden: hidden,
      meta: {title: '首页', icon: 'dashboard',}
    }]

  },

  {
    path: '/company',
    component: Layout,
    redirect: '/company',
    name: 'Company',
    meta: {title: '招聘求职', icon: 'el-icon-s-cooperation'},
    children: [
      {
        path: 'companyList',
        name: 'CompanyList',
        hidden: hidden,
        meta: {title: '企业信息', icon: 'el-icon-s-platform'},
        component: () => import('@/views/company/index')
      },
      {
        path: 'position',
        name: 'Position',
        meta: {title: '职位审核', icon: 'el-icon-tickets'},
        hidden: hidden,
        component: () => import('@/views/company/position')
      },
      {
        path: 'introduce',
        name: 'Introduce',
        meta: {title: '简历投递信息', icon: 'el-icon-s-custom'},
        hidden: hidden2,
        component: () => import('@/views/introduce/index')
      },
      {
        path: 'personnel',
        name: 'Personnel',
        meta: {title: '招聘人员审核', icon: 'el-icon-user-solid', affix: true},
        hidden: hidden,
        component: () => import('@/views/personnel/index')
      },
      {
        path: 'customerList',
        name: 'CustomerList',
        meta: {title: '求职人员列表', icon: 'el-icon-s-custom'},
        hidden: hidden,
        component: () => import('@/views/customer/index')
      },
      {
        path: 'intermediary',
        name: 'Intermediary',
        meta: {title: '中介机构管理', icon: 'el-icon-s-shop'},
        hidden: hidden,
        component: () => import('@/views/intermediary/index')
      },
      {
        path: 'jobFairs',
        name: 'JobFairs',
        meta: {title: '招聘会列表', icon: 'el-icon-office-building'},
        hidden: hidden,
        component: () => import('@/views/jobFairs/index')
      },
      {
        path: 'livePortend',
        name: 'LivePortend',
        hidden: hidden,
        meta: {title: '直播预告', icon: 'el-icon-video-camera'},

        component: () => import('@/views/livePortend/index')
      },
      {
        path: 'jobFairsPublish',
        name: 'JobFairsComPublish',
        meta: {title: '参会岗位', activeMenu: `/jobFairs/jobFairsPublish`},
        hidden: true,
        component: () => import('@/views/jobFairs/jobFairsPublish')
      },
      {
        path: '/entrepreneurship_expert',
        component: MechanicOrder,
        hidden: hidden,
        meta: {title: '创业服务管理', icon: 'el-icon-s-shop'},
        children: [
          {
            path: 'entrepreneurship',
            name: 'Entrepreneurship',
            meta: {title: '孵化基地', icon: 'el-icon-coordinate'},
            component: () => import('@/views/entrepreneurship/index')
          },

        ],
      },
      {
        path: 'School',
        name: 'School',
        meta: {title: '学校信息管理', icon: 'el-icon-s-marketing'},
        hidden: hidden,
        component: () => import('@/views/school/index')
      },
      {
        path: 'major',
        name: 'Major',
        meta: {title: '学校专业', activeMenu: `/school/major`},
        hidden: true,
        component: () => import('@/views/school/major')
      },
      {
        path: 'jobFairsPublish',
        name: 'JobFairsComPublish',
        meta: {title: '参会岗位', activeMenu: `/jobFairs/jobFairsPublish`},
        hidden: true,
        component: () => import('@/views/jobFairs/jobFairsPublish')
      }
    ],
  },
  {
    path: '/article-code',
    component: Layout,
    name: 'PlaceCode',
    children: [
      {
        path: 'article',
        name: 'article',
        meta: {title: '文章管理', icon: 'el-icon-s-grid'},
        component: () => import('@/views/article-code/index')
      }
    ],
    hidden: hidden,
  },
  {
    path: '/train',
    component: Layout,
    redirect: '/train',
    name: 'Train',
    meta: {title: '技能培训管理', icon: 'el-icon-s-help'},

    children: [
      {
        path: 'trainList',
        name: 'TrainList',
        hidden: hidden3,
        meta: {title: '技能培训', icon: 'el-icon-medal-1'},
        component: () => import('@/views/train/index')
      },
      {
        path: 'trainManage',
        name: 'TrainManage',
        hidden: hidden,
        meta: {title: '专业管理', icon: 'el-icon-edit'},
        component: () => import('@/views/train/list')
      },
    ],
  },
  {
    path: '/report',
    component: Layout,
    redirect: '/report',
    name: 'Train',
    meta: {title: '运营管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'reportList',
        name: 'ReportList',
        hidden: hidden,
        meta: {title: '举报信息管理', icon: 'el-icon-info'},
        component: () => import('@/views/report/index')
      },
      {
        path: 'advertisement',
        name: 'Advertisement',
        hidden: hidden,
        meta: {title: '广告管理', icon: 'el-icon-s-opportunity'},
        component: () => import('@/views/advertisement/index')
      },
      {
        path: 'questionnaireInvestigation',
        name: 'questionnaireInvestigation',
        hidden: hidden4,
        meta: {title: '未就业/劳动力管理', icon: 'el-icon-s-order', affix: true},
        component: () => import('@/views/questionnaireInvestigation/index')
      },
      {
        path: 'questionnaireInvestigation2',
        name: 'questionnaireInvestigation2',
        hidden: hidden,
        meta: {title: '帮扶三次未就业人员管理', icon: 'el-icon-s-order',},
        component: () => import('@/views/questionnaireInvestigation2/index')
      },
      {
        path: 'areaStatistics',
        name: 'areaStatistics',
        hidden: hidden,
        meta: {title: '个人街道社区数据统计', icon: 'el-icon-data-line',},
        component: () => import('@/views/areaStatistics/index')
      },
      {
        path: 'comStatistics',
        name: 'comStatistics',
        hidden: hidden,
        meta: {title: '企业街道社区数据统计', icon: 'el-icon-data-analysis',},
        component: () => import('@/views/comStatistics/index')
      },
      {
        path: 'subsidyApplication',
        name: 'SubsidyApplication',
        hidden: hidden,
        meta: {title: '⼤学⽣进企业补助申领', icon: 'el-icon-s-opportunity'},
        component: () => import('@/views/subsidyApplication/index')
      },
      {
        path: 'enjoyingEnterpriseSubsidies',
        name: 'EnjoyingEnterpriseSubsidies',
        hidden: hidden6,
        meta: {title: '享受企业补贴学生名单', icon: 'el-icon-s-opportunity'},
        component: () => import('@/views/enjoyingEnterpriseSubsidies/index')
      },
    ],
  },

  {
    path: '/setUp',
    component: Layout,
    redirect: '/setUp',
    name: 'Train',
    meta: {title: '系统配置', icon: 'el-icon-s-tools'},
    children: [
      {
        path: 'newsType',
        name: 'NewsType',
        meta: {title: '新闻分类管理', icon: 'el-icon-s-unfold'},
        component: () => import('@/views/newsType/index')
      },
      {
        path: 'industry',
        name: 'Industry',
        meta: {title: '行业分类管理', icon: 'el-icon-s-operation'},
        component: () => import('@/views/position/index')
      },

    ],
    hidden: hidden,
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
